﻿Imports System.Data.OleDb
Public Class Experience_Detail
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        'Making sure we haven't arrived here from the same page but from somewhere else, before proceeding.

        If IsPostBack = False Then

            'The following code is needed to update comment list as soon as the user submits them.

            If Request.Params("ID") = "" Then
                Response.Redirect("Experiences_All.aspx")
            End If
            Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("TravellingAloneConnectionString").ConnectionString)
            Dim SqlString As String = "SELECT * FROM experiences_comments WHERE experience_fkid = @f1"
            Dim cmd As OleDbCommand = New OleDbCommand(SqlString, oleDbConn)
            cmd.CommandType = CommandType.Text
            cmd.Parameters.AddWithValue("@f1", Request.Params("ID"))
            oleDbConn.Open()
            Dim dataReader = cmd.ExecuteReader()
            GridView2.DataSource = dataReader
            GridView2.DataBind()

        End If

    End Sub

    Protected Sub btn_submit_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn_submit.Click
        Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("TravellingAloneConnectionString").ConnectionString)
        Dim SqlString As String = "Insert into experiences_comments(the_author, the_comment, experience_fkid) Values (@f1, @f2, @f3)"
        Dim cmd As OleDbCommand = New OleDbCommand(SqlString, oleDbConn)
        cmd.CommandType = CommandType.Text
        cmd.Parameters.AddWithValue("@f1", User.Identity.Name)
        cmd.Parameters.AddWithValue("@f2", tb_comment.Text)
        cmd.Parameters.AddWithValue("@f3", Request.Params("ID"))
        oleDbConn.Open()
        cmd.ExecuteNonQuery()
        Response.Redirect("Default.aspx")
    End Sub
End Class